<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      background-color: #000;
    }

    /* 动画实现的效果是随着progress的增加，白色部分越来越少，绿色部分越来越多 */
    h1 {
      --progress: 0;
      width: 420px;
      margin: 0 auto;
      font-size: 60px;
      color: transparent;
      font-family: Helvetica, sans-serif;
      letter-spacing: -3px;
      background-image: linear-gradient(#fff calc(100% - calc(var(--progress) * 100%)), #4cd265 calc(100% - calc(var(--progress) * 100%)));
      background-clip: text;
      /* background-image: linear-gradient(#fff 40%, #4cd265 20%); */

      -webkit-background-clip: text;
      /* clamp的选值区间 -1.35到1.35  -1.35小于左边所以取左边，1.35大于右边所以取右边*/
      transform: scale(clamp(1, calc((var(--progress) - 0.99) * 135), 1.3));
      transition: .3s transform ease-out;
    }

    .buttons {
      position: absolute;
      bottom: 0;
      padding: 20px;
    }

    .buttons button {
      display: inline-block;
      font-size: 32px;
      background-color: #fff;
      border: 0;
      padding: 10px 20px;
      border-radius: 12px;
      margin: 0 10px;
    }
  </style>
</head>

<body>
  <h1>Up to 20 hours of battery life — the longest in any Mac ever.</h1>

  <div class="buttons">
    <button id="empty">0%</button>
    <button id="full">100%</button>
  </div>

  <script>
    let progress = 0

    function run() {
      if (progress < 1) {
        progress = parseFloat((progress + 0.01).toFixed(2))

        document.querySelector('h1').style.setProperty('--progress', progress)

        setTimeout(run, 20)
      }
    }

    document.querySelector('#empty').addEventListener('click', (e) => {
      progress = 0
      document.querySelector('h1').style.setProperty('--progress', progress)
    })

    document.querySelector('#full').addEventListener('click', (e) => {
      run()
    })
  </script>
</body>

</html>